package courses;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * 课程类
 */
public class Course {

    /**
     * 课程ID
     */
    private String courseid;

    /**
     * 课程名称
     */
    private String coursename;

    /**
     * 讲师
     */
    private String lecturer;

    /**
     * 上课日
     */
    private String classday;

    /**
     * 开始时间
     */
    private String begintime;

    /**
     * 结束时间
     */
    private String endtime;

    /**
     * 课程最大人数
     */
    private String maxNum;

    public String getCourseid() {
        return courseid;
    }

    public void setCourseid(String courseid) {
        this.courseid = courseid;
    }

    public String getCoursename() {
        return coursename;
    }

    public void setCoursename(String coursename) {
        this.coursename = coursename;
    }

    public String getLecturer() {
        return lecturer;
    }

    public void setLecturer(String lecturer) {
        this.lecturer = lecturer;
    }

    public String getClassday() {
        return classday;
    }

    public void setClassday(String classday) {
        this.classday = classday;
    }

    public String getBegintime() {
        return begintime;
    }

    public void setBegintime(String begintime) {
        this.begintime = begintime;
    }

    public String getEndtime() {
        return endtime;
    }

    public void setEndtime(String endtime) {
        this.endtime = endtime;
    }

    public String getMaxNum() {
        return maxNum;
    }

    public void setMaxNum(String maxNum) {
        this.maxNum = maxNum;
    }

    public Course(String courseid, String coursename, String lecturer, String classday, String begintime, String endtime, String maxNum) {
        this.courseid = courseid;
        this.coursename = coursename;
        this.lecturer = lecturer;
        this.classday = classday;
        this.begintime = begintime;
        this.endtime = endtime;
        this.maxNum = maxNum;
    }

    public Course() {

    }


    /**
     * 检测当前课程ID是否存在ID
     */
    public static Course exitCourseId(String courseid, List<Course> courseList){
        //检测当前课程ID是否存在系统
        Optional<Course> courseOptional = courseList.stream()
                .filter(course -> course.getCourseid().equals(courseid))
                .findFirst();
        if(courseOptional.isPresent()){
            return courseOptional.get();
        }
        return null;
    }

    /**
     * 根据教授名称获取他负责的所有课程
     */
    public static List<Course> exitCourseName(String name, List<Course> courseList){
       List<Course> courseOptional = courseList.stream()
                .filter(course -> course.getLecturer().equals(name))
                .collect(Collectors.toList());
        return courseOptional;
    }


}
